package jm.nj.demo09mian.demo02;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;

/*
*java.util.LinkedHashMap集合  继承 HashMap
 * LinkedHashMap集合:
 * 	哈希表+链表的组合:可以保证迭代的顺序(元素存储和取出的顺序一致)
 * 	不是同步的,多线程,速度快
 *  JDK1.4版本之后出现的
*
* */
public class Demo02LinkedHashMap {
    public static void main(String[] args) {
        HashMap<String,String>map = new HashMap<String, String>();
        map.put("a","1");
        map.put("c","8");
        map.put("b","9");
        map.put("d","1");
        for (String s : map.keySet()) {
            System.out.println(s+":"+map.get(s));
        }

        System.out.println("------------------");

        //LinkedHashMap是一个有序的集合
        LinkedHashMap<String,String>linked = new LinkedHashMap<String, String>();
        linked.put("a","1");
        linked.put("b","2");
        linked.put("d","4");
        linked.put("c","3");
        for (String s : linked.keySet()) {
            System.out.println(s+":"+linked.get(s));
        }
    }
}
